package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.Privilege;
import com.sc.nft.entity.vo.CollectionPrivilegeVO;
import com.sc.nft.mapper.PrivilegeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 权益配置表(sc_privilege)数据DAO
 *
 * @author kancy
 * @since 2022-06-29 00:20:30
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class PrivilegeDao extends ServiceImpl<PrivilegeMapper, Privilege> {

    public Privilege getByName(String name){
        LambdaQueryWrapper<Privilege> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Privilege::getName,name);
        return getOne(wrapper);
    }

    public Privilege getByLevel(Integer level){
        LambdaQueryWrapper<Privilege> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Privilege::getLevel,level);
        return getOne(wrapper);
    }

    public Privilege getByCollectionId(Long id){
        LambdaQueryWrapper<Privilege> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Privilege::getCollectionId,id);
        return getOne(wrapper);
    }


    public List<Privilege> getPrivilegeByCollectionId(Long collectionId) {
        LambdaQueryWrapper<Privilege> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Privilege::getCollectionId,collectionId);
        return list(wrapper);
    }

    public Page<CollectionPrivilegeVO> collectionPrivilege(int pageNo, int pageSize,Long collectionId) {
        return baseMapper.collectionPrivilege(new Page(pageNo,pageSize),collectionId);
    }
    public Privilege getByUserLevel(Integer level) {
        QueryWrapper<Privilege> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("level",level);
        Privilege privilege=(Privilege)new Privilege().selectOne(queryWrapper);
        return privilege;
    }
}